package yxy.game.pm2.command.therionHunting;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.TherionHuntingMessage;
import yxy.game.pm2.module.therionHunting.TherionHandle;

/**
 * @name CMD_TherionPlayerChallengeRecord
 * @author wrs
 * @descrition 神兽玩法玩家挑战记录
 * @since 2022-06-20
 */
@MessageType(proto = Command.TherionPlayerChallengeRecord ,classtype = TherionHuntingMessage.TherionPlayerChallengeRecordRequest.class)
public class CMD_TherionPlayerChallengeRecord extends Command<TherionHuntingMessage.TherionPlayerChallengeRecordRequest> {

    @Override
    public void execute(MessageSource messageSource, TherionHuntingMessage.TherionPlayerChallengeRecordRequest request) throws Exception {
        String playerCode = messageSource.getTag();

        TherionHuntingMessage.TherionPlayerChallengeRecordResponse.Builder response = TherionHuntingMessage.TherionPlayerChallengeRecordResponse.newBuilder();

        try {
            Result result = new TherionHandle().record(playerCode, response);
            send(messageSource, response, result);
        }catch (Exception e){
            e.printStackTrace();
            send(messageSource,response, Result.DataError);
        }
    }

    private void send(MessageSource messageSource, TherionHuntingMessage.TherionPlayerChallengeRecordResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
